﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using padnug.Domain;
using PadnugFramework;
using PadnugRepositoryInterfaces;

namespace PadnugRepository
{
    public class PadnugSponsorsRepository : IPadnugSponsorsRepository
    {
        private padnugEntities db;

        public PadnugSponsorsRepository()
        {
            db = new padnugEntities();
        }

        public IList<padnug.Domain.Sponsor> GetPremimumSponsors()
        {
            IList<padnug.Domain.Sponsor> sponsorList = new List<padnug.Domain.Sponsor>();
            var dbSponsors = db.Sponsors.Where(s => s.IsPremium).OrderBy(s=>s.ExpirationDate);
            foreach (var s in dbSponsors)
            {
                padnug.Domain.Sponsor padnugSponsor = new padnug.Domain.Sponsor
                {
                    ExpirationDate = s.ExpirationDate,
                    IsPremimum = s.IsPremium,
                    SponsorID = s.SponsorID,
                    SponsorLargeImage = s.SponsorLargeImage,
                    SponsorName = s.SponsorName,
                    SponsorSmallImage = s.SponsorSmallImage,
                    SponsorURL = s.SponsorURL
                };

                sponsorList.Add(padnugSponsor);
            }

            return sponsorList;
        }

        public IList<padnug.Domain.Sponsor> GetRegularSponsors()
        {
            var today = DateTime.Now;
            IList<padnug.Domain.Sponsor> sponsorList = new List<padnug.Domain.Sponsor>();
            var dbSponsors = db.Sponsors.Where(s => (s.IsPremium == false) && (s.ExpirationDate >= today)).OrderBy(s => s.ExpirationDate);
            foreach (var s in dbSponsors)
            {
                padnug.Domain.Sponsor padnugSponsor = new padnug.Domain.Sponsor
                {
                    ExpirationDate = s.ExpirationDate,
                    IsPremimum = s.IsPremium,
                    SponsorID = s.SponsorID,
                    SponsorLargeImage = s.SponsorLargeImage,
                    SponsorName = s.SponsorName,
                    SponsorSmallImage = s.SponsorSmallImage,
                    SponsorURL = s.SponsorURL
                };

                sponsorList.Add(padnugSponsor);
            }

            return sponsorList;
        }

        public IList<padnug.Domain.Sponsor> GetAllSponsors()
        {
            IList<padnug.Domain.Sponsor> sponsorList = new List<padnug.Domain.Sponsor>();
            foreach (var s in db.Sponsors)
            {
                padnug.Domain.Sponsor padnugSponsor = new padnug.Domain.Sponsor
                {
                    ExpirationDate = s.ExpirationDate,
                    IsPremimum = s.IsPremium,
                    SponsorID = s.SponsorID,
                    SponsorLargeImage = s.SponsorLargeImage,
                    SponsorName = s.SponsorName,
                    SponsorSmallImage = s.SponsorSmallImage,
                    SponsorURL = s.SponsorURL
                };

                sponsorList.Add(padnugSponsor);
            }
            return sponsorList;
        }

        public void AddNewSponsor(padnug.Domain.Sponsor sponsor)
        {
            throw new NotImplementedException();
        }

        public void UpdateSponsor(padnug.Domain.Sponsor sponsor)
        {
            throw new NotImplementedException();
        }

        public void DeleteSponsor(padnug.Domain.Sponsor sponsor)
        {
            throw new NotImplementedException();
        }
    }
}
